//单页长时间不操作就会自动退出
/*  
var lastTime = new Date().getTime()
var currentTime = new Date().getTime()
var timeOut = 10 * 60 *1000  //设置超时时间: 30分
 
window.onload = function() {
	window.document.onmousedown = function() {
		localStorage.setItem("lastTime",new Date().getTime())
	}
};
 
function checkTimeout() {
	currentTime = new Date().getTime()		//更新当前时间
    console.log(currentTime);
	lastTime = localStorage.getItem("lastTime");
	// console.log(currentTime - lastTime);
	// console.log(timeOut);
	if (currentTime - lastTime > timeOut) { //判断是否超时
		// console.log("超时");
		var url = window.location.href;
		var newUrl=url.match(/(\S*)#/);
		sessionStorage.clear()
		alert('登录超时，请重新登陆')
		location.href = '#/login';
	}
} */
 
 
/* 定时器 间隔30秒检测是否长时间未操作页面 */
// window.setInterval(checkTimeout, 30000);

// 动态路由
/**
 * 递归过滤路由配置，移除所有 children 中没有 path 字段的对象
 * @param {Array} routes 原始路由配置
 * @returns {Array} 过滤后的有效路由配置
 */
export function filterRoutes(routes) {
  return routes
	// 1. 过滤掉自身没有 path 的路由对象
	.filter(route => !!route.path)
	// 2. 处理子路由
	.map(route => {
	  const newRoute = { ...route };
	  if (newRoute.children) {
		// 递归过滤子路由，并移除处理后为空的 children
		newRoute.children = filterRoutes(newRoute.children);
		if (newRoute.children.length === 0) {
		  delete newRoute.children; // 可选：若子路由为空，删除 children 字段
		}
	  }
	  return newRoute;
	});
};

// src/utils/dynamic-routes.js
export function generateRoutes(routesData) {
  return routesData.map(routeData => {
    const route = {
      path: routeData.path,
      name: routeData.name,
      meta: routeData.meta || { requiresAuth: true }
    };

    if (routeData.component) {
      route.component = () => import(`@/views/${routeData.component}`);
    }

    if (routeData.children) {
      route.children = generateRoutes(routeData.children);
    }

    return route;
  });
}